<template>
  <div class="app-container">
    <el-form ref="form" :model="option" label-width="120px">
      <el-form-item label="买家ID">
        <el-input v-model="option.userId" />
      </el-form-item>
      <el-form-item label="卖家ID">
        <el-input v-model="option.sell" />
      </el-form-item>
      <el-form-item label="商品从属ID">
        <el-input v-model="option.articleId" />
      </el-form-item>
      <el-form-item label="总价">
        <el-input v-model="option.totle" style="width: 200px" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">新增</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import orderApi from "../../api/orders.js";
export default {
  data() {
    return {
      option: {
        time: "",
        totle: "",
        articleId: "60a5ca0a82c8733c18b1e89d",
        userId: "60a353bad1daad0ae81d7138",//买家ID
        sell:"60a353bad1daad0ae81d7138",//卖家ID
      },
    };
  },
  methods: {
    onSubmit() {
      if (isNaN(this.option.articleId && this.option.userId&&this.option.sell)) {
        this.option = {
          time: new Date().getTime(),
          totle: this.option.totle,
          articleId: "60a5ca0a82c8733c18b1e89d",
          userId: "60a353bad1daad0ae81d7138",
        sell:"60a353bad1daad0ae81d7138",//卖家ID
        };
        console.log(1111111);
        orderApi.add(this.option);
        this.option = {
          time: "",
          totle: "",
          articleId: "",
          userId: "",
          sell:"",
        };
       this.$router.push({name:'Orders'})

      } else {
        this.option.time=new Date().getTime();
        orderApi.add(this.option);
        console.log(this.option);
       this.$router.push({name:'Orders'})

      }

    },
  },
  created() {
    this.option = this.$route.params;
  },
};
</script>

<style scoped>
.line {
  text-align: center;
}
</style>

